//
//  YWSelectEquipmentSystemTableViewController.m
//  maintain
//
//  Created by Kyo on 16/9/8.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWSelectEquipmentSystemTableViewController.h"
#import "UIColor+CustomColors.h"
#import "YWMacro.h"

#import "YWEquipmentType.h"
#import "YWEquipmentManager.h"

#import "YWSelectEquipmentTypeTableViewController.h"
#import "YWSelectEquTypeMultiTVC.h"

@interface YWSelectEquipmentSystemTableViewController ()
@property (nonatomic, strong) NSArray *allEquipmentSystemType;
@end

@implementation YWSelectEquipmentSystemTableViewController
- (instancetype)init{
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalizedString(@"selectEquipmentSystemType", nil);//@"选择设备系统类型";
    self.tableView.backgroundColor = [UIColor customBackgroudColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSArray *)allEquipmentSystemType{
    if (!_allEquipmentSystemType) {
        _allEquipmentSystemType = [[NSArray alloc] initWithArray:[[YWEquipmentManager shareManager] allEquipmentSystemType]];
    }
    return _allEquipmentSystemType;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.allEquipmentSystemType count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId  = @"equipmentSystemTypeReuseIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font = kContentFont;
    }
    YWEquipmentSystemType *sysTemType = self.allEquipmentSystemType[indexPath.row];
    cell.textLabel.text = sysTemType.systemTypeName?:@"";
    // Configure the cell...
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    YWEquipmentSystemType *sysTemType = self.allEquipmentSystemType[indexPath.row];
    if (_isFromSubscripVC) {
        YWSelectEquTypeMultiTVC *selectEquipmentTypeVC = [[YWSelectEquTypeMultiTVC alloc] init];
        selectEquipmentTypeVC.sysTemType = sysTemType;
        selectEquipmentTypeVC.haveSelEquTypeArray = self.equipmentTypeArray;
        [self.navigationController pushViewController:selectEquipmentTypeVC animated:YES];

    }else{
        YWSelectEquipmentTypeTableViewController *selectEquipmentTypeVC = [[YWSelectEquipmentTypeTableViewController alloc] init];
        //__weak typeof(self.assignMissionTableVC) weakSelf = self.assignMissionTableVC;
        selectEquipmentTypeVC.delegate = (id<YWSelectEquipmentTypeTableViewControllerDelegate>)self.assignMissionTableVC;
        selectEquipmentTypeVC.sysTemType = sysTemType;
        selectEquipmentTypeVC.assignMissionTableVC = self.assignMissionTableVC;
        [self.navigationController pushViewController:selectEquipmentTypeVC animated:YES];
    }
}
@end
